import 'package:flutter/material.dart';

//公共表单控件
class CommonFormItem extends StatelessWidget {
  final String label; //标题
  final Widget Function(BuildContext context) contentBuilder;
  final Widget suffix; //尾缀
  final String suffixText; //尾缀文本
  final String hintText;
  final ValueChanged onChanged;
  final TextEditingController controller;

  const CommonFormItem(
      {Key key,
      this.label,
      this.contentBuilder,
      this.suffix,
      this.suffixText,
      this.hintText,
      this.onChanged,
      this.controller})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  width: 1.0, color: Theme.of(context).disabledColor))),
      child: Row(
        children: [
          Container(
            width: 100,
            child: Text(
              label,
              style: TextStyle(
                fontSize: 16.0,
                color: Colors.black87,
              ),
            ),
          ),
          Expanded(
              child: contentBuilder != null
                  ? contentBuilder(context)
                  : TextField(
                      controller: controller,
                      decoration: InputDecoration(
                          border: InputBorder.none, //去掉文本输入框下划线
                          hintText: hintText),
                    )),
          if (suffix != null) suffix,
          if (suffix == null && suffixText != null) Text(suffixText)
        ],
      ),
    );
  }
}
